package com.nageoffer.shortlink.project.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nageoffer.shortlink.project.dao.entity.LinkAccessStatsDO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;

/**
 * ClassName: LinkAccessStatsMapper
 * Package: com.nageoffer.shortlink.project.dao.mapper
 * Description:
 *
 * @Author Jetson
 * @Create 2024/10/28 16:41
 * @Version 1.0
 */
public interface LinkAccessStatsMapper extends BaseMapper<LinkAccessStatsDO> {
    /**
     * 记录基础监控访问数据
     */
    @Insert("INSERT INTO t_link_access_stats (full_short_url,\n" +
            "        gid,\n" +
            "        date,\n" +
            "        pv,\n" +
            "        uv,\n" +
            "        uip,\n" +
            "        hour,\n" +
            "        weekday,\n" +
            "        create_time,\n" +
            "        update_time,\n" +
            "        del_flag)\n" +
            "VALUES (#{linkAccessStats.fullShortUrl},\n" +
            "        #{linkAccessStats.gid},\n" +
            "        #{linkAccessStats.date},\n" +
            "        #{linkAccessStats.pv},\n" +
            "        #{linkAccessStats.uv},\n" +
            "        #{linkAccessStats.uip},\n" +
            "        #{linkAccessStats.hour},\n" +
            "        #{linkAccessStats.weekday},\n" +
            "        NOW(),\n" +
            "        NOW(),\n" +
            "        0)\n" +
            "ON DUPLICATE KEY\n" +
            "    UPDATE pv  = pv + #{linkAccessStats.pv},\n" +
            "           uv  = uv + #{linkAccessStats.uv},\n" +
            "           uip = uip + #{linkAccessStats.uip};")
    // @Param注解意思是将后面这个变量 名称转变为 LinkAccessStats
    void shortLinkStats(@Param("linkAccessStats") LinkAccessStatsDO linkAccessStatsDO);
}
